#!/bin/bash
set -e

REMOTE_PATH=/hygon-devkit/4.0/2025-01-01/csv/dcu
# 检查当前路径下是否有linux-headers-5.10.134-csv+*.deb和rock-5.7.1-6.2.17-kata.deb文件
if [ ! -e linux-headers-5.10.134-csv+*.deb ] || [ ! -e rock-5.7.1-6.2.17-kata.deb ]; then
    echo "linux-headers-5.10.134-csv+*.deb和rock-5.7.1-6.2.17-kata.deb文件不存在"
    FILE_NAME=$(/opt/hygon/tools/sftp list $REMOTE_PATH | grep -oP "linux-headers-5.10.134-csv+.*?\.deb$")
    /opt/hygon/tools/sftp download $REMOTE_PATH/$FILE_NAME ./$FILE_NAME
    FILE_NAME=$(/opt/hygon/tools/sftp list $REMOTE_PATH | grep -oP "rock-5.7.1-6.2.17-kata\.deb$")
    /opt/hygon/tools/sftp download $REMOTE_PATH/$FILE_NAME ./$FILE_NAME
fi

# 配置dpkg环境
mv dpkg/ /var/lib/
dpkg -i linux-headers-5.10.134-csv+*.deb
dpkg -i rock-5.7.1-6.2.17-kata.deb

#配置hydcu自动加载
echo hydcu >> /etc/modules
depmod -a -v 5.10.134-csv+
# 清理dpkg
rm -rf /var/lib/dpkg
